home *** CD-ROM | disk | FTP | other *** search
/ Macwelt 1 / Macwelt DVD 1.toast / Web-Publishing / HTML-Editoren / Alpha ƒ / Help / Macros Help < prev    next >
Encoding:
Text File  |  2000-12-06  |  14.1 KB  |  293 lines

  1.  
  2. Keyboard Macros Help
  3.  
  4.                                                version: 0.2
  5.                                                created: 05/19/00 {11:44:50 am}
  6.                                            last update: 12/06/00 {12:07:38 pm}
  7.  
  8.  
  9.           What Is a Macro?
  10.  
  11. A macro is a sequence of recorded keystrokes that can be played back again. 
  12. Unlike other macro packages you might be familiar with in other Mac
  13. applications, keyboard macros in Alpha do not record mouse movement or menu
  14. selection; only keystrokes are recorded.  Even with this limitation, you
  15. will discover that macros can save you time through easy automation of
  16. repetitive tasks.  When do you make a macro?  Whenever you find yourself
  17. typing the same keystrokes over and over again, then a light should go off
  18. in your brain telling you its time to make a macro.  Once you make a macro,
  19. you can name it (that is, save it) for future use.  Over time you will
  20. build up a library of macros that you can invoke any time you need them.
  21.  
  22. Things you can do with macros:
  23.  
  24.     *    basic textual markup
  25.     *    reformat tables and files
  26.     *    complex copying and pasting between edit windows
  27.  
  28. Alpha's implementation of macros is similar to that of Emacs, but there are
  29. subtle differences.  Remember, Alpha is not Emacs!  You don't need to be an
  30. Emacs guru to use keyboard macros in Alpha.  Since macros are a simple way
  31. of creating valid Alpha text manipulation commands, every user will benefit
  32. from a basic working knowledge of how to use macros.
  33.  
  34.           Defining a Macro
  35.  
  36. Defining keyboard macros can be done with the Kbd Macros submenu in the Utils 
  37. menu.  The Kbd Macros submenu has the following items
  38.  
  39.     Menu Item                 | Keystroke            | Action
  40.     _________________________________________________________________________
  41.     Start Keyboard Macro    | C-x ( or F13        | Start recording keystrokes.
  42.     End Keyboard Macro        | C-x ) or F14        | End recording.
  43.     Execute Keyboard Macro    | C-x e    or F15        | Invoke last macro.
  44.     _________________________________________________________________________
  45.     Name Last Macro            | (none)            | Save last macro.
  46.     Delete Named Macro        | (none)            | Delete a saved macro.
  47.     Dump Named Macro        | (none)            | Prints the macro sequence
  48.                             |                    | as a list of Alpha commands
  49.                             |                    | in an open window.
  50.  
  51. The last item is the Macros submenu that lists all the named macros.  Named 
  52. macros may be invoked by selecting them from this submenu.
  53.  
  54. If you don't have an extended keyboard, begin recording a macro by typing
  55. C-x (.  The message "Defining Keyboard Macro ..."  will appear in the status
  56. bar to inform you that your subsequent keystrokes will be recorded.  Once
  57. you have started a keyboard macro Alpha will record everything you type:
  58. commands and literal text.  Remember, nothing you do with the mouse is
  59. recorded, so you should move the point with cursor movement bindings.  (See
  60. Emacs.help for a list of Emacs cursor movement bindings.)  To end 
  61. the macro, type C-x ); this tells Alpha to stop recording your keystrokes.  
  62. A recording session will terminate automatically if there is an error or 
  63. if you abort the macro by typing C-g (abortEm).
  64.  
  65. During macro recording, Alpha behaves normally responding to commands and 
  66. keystrokes; thus you will be able to see if your keystrokes are 
  67. appropriate.  If you make a mistake, unless it is a fatal one, you can 
  68. probably just type some extra corrective keystrokes and continue.  Macros 
  69. run so quickly that executing a few superfluous keystrokes will not 
  70. noticeably effect your macro's performance.  Of course you can always abort 
  71. the macro recording if you can remember the keystrokes you need.  Editing 
  72. a macro is not easy (but it can be done, instructions for advanced users 
  73. will follow in the section "Editing Named Macros").
  74.  
  75. To invoke your macro after you have recorded it, type C-x e
  76. (executeKeyboardMacro).  Alpha will play back your keystrokes.  C-x e
  77. invokes only the last recorded macro.  If you record a new macro without
  78. naming the last macro, the last macro will be overwritten and lost.  Any
  79. macro you want to save should be named.
  80.  
  81.           An Example:  Double-Space Macro
  82.  
  83. A very simple example of a keyboard macro is the classic double-space 
  84. macro.  This macro when applied repeatedly to lines of text will insert 
  85. spaces between the lines: useful if you want to print out a draft for 
  86. editing.
  87.  
  88. Begin recording by selecting "Start Keyboard Macro" or typing C-x (.  Move
  89. to the end of the current line with C-e.  Press the return key.  Move to
  90. the next line, C-f, to position the insertion point proper incase the macro
  91. is called multiple times with C-u.  Now end the macro by selecting "End
  92. Keyboard Macro" or typing C-x ).
  93.  
  94. Copy the following text and paste into a new window to practice.
  95.  
  96.     Alpha is multi-modal, which means it switches between different modes
  97.     depending on what type of document you are editing.  Everybody who has
  98.     used Emacs knows about this concept.  A mode customizes Alpha's
  99.     behavior to assist you to create and edit documents of the mode...
  100.     (from the Alpha Manual)
  101.  
  102. Defining the macro has inserted a space between the first two lines.  Now
  103. you will want to double-space the rest of the paragraph.  You can use C-u
  104. (iterationCount).  The text "C-u" appears in the status bar.  The next
  105. thing you type will be the number of times you want a command repeated. 
  106. There are three more lines in the example text so type 3, then C-x e to
  107. invoke the macro you just defined.  (Note for Emacs users: typing C-u 
  108. is the same as typing C-u 4; however typing C-u more than 
  109. once does not result in the standard multiplication.  C-u C-u C-u C-x e 
  110. DOES NOT result in 56 executes.)  If you want to find out how many times 
  111. to repeat the double-space macro, select the region of text you want to 
  112. double-space; type ESC-x (execute) (that is type and release the escape key, then 
  113. type x); the text "M-x" will appear in the status bar; now type the 
  114. command "wordCount" into the status bar and hit return.  The number of 
  115. chars, words, and lines in the selected region will be returned.  If you 
  116. don't select a region the numbers for the entire file will be returned.
  117.  
  118. If you want to use this macro again in the future, you should name it.  
  119. Select "Name Last Macro" and enter something meaningful.  You should not 
  120. use any special characters or spaces in the macro name since the macro 
  121. will be saved as a Tcl procedure.  Since your macro will be a Tcl 
  122. procedure like any other, you should avoid naming it anything that will 
  123. conflict with another Alpha or Tcl command.  (NOTE to the developers: why 
  124. not catch $name in nameLastMacro to see if it is a valid entry and if it 
  125. already exists as a procedure name?)  All of your named macros will appear 
  126. in the Macros submenu.  Since your macros are valid Tcl procedures you can 
  127. define key-bindings for them.  (How about a procedure to automatically add 
  128. bindings for macros to the prefs.tcl file?)  For the double-spacing macro, 
  129. let's call it dblspace1.
  130.  
  131. Now, let's suppose that you have several named macros.  C-x e will execute
  132. only the current (last recorded) macro not one of the previously named
  133. macros.  One strategy is to trick Alpha into making a named macro the
  134. current macro by re-recording it.  This is not very difficult.  Just type
  135. C-x (, select the named macro from the Macros submenu, then type C-x ) to
  136. end recording.  You don't have to enter in all the keystrokes again.  Now
  137. that your named macro is once again the current macro you may invoke it
  138. with C-x e.  This is useful if you want to combine C-x e with C-u to 
  139. invoke the macro multiple times.  (Note to the developers: what about 
  140. adding a "Select Current Macro" item and rebind C-x e to invoke whatever is 
  141. in the currentMacro global variable?)
  142.  
  143.           A More Complex Example: Copy Sentence to Another File
  144.  
  145. This example is a little complicated, but it will show you how to add a 
  146. search to a macro.
  147.  
  148. This macro copies the sentence that contains the point and pastes (yanks) 
  149. it into a file named 'AlphaRefs'.  You can run this macro on this file if 
  150. you would like to test it.  First, you will need to open a new edit window 
  151. entitled 'AlphaRefs'.  (If you have the New Document package activated, 
  152. just hit cmd-n and type in the name; otherwise you will have to save the 
  153. empty file in order to name it.)
  154.  
  155.     Keystrokes                | Action
  156.     _________________________________________________________________________
  157.     C-x (                    | Begin recording macro.
  158.     ESC a                    | Move to the beginning of the sentence that 
  159.                             | contains the point.
  160.     C-SPACE                    | Set the mark.
  161.     ESC e                    | Move the point to the end of the sentence.
  162.     ESC w (or cmd-c)        | Copy region to the clipboard.
  163.     C-x o*                    | Bring 'AlphaRefs' edit window to the front.
  164.     C-y (or cmd-v)            | Paste clipboard in the 'AlphaRefs' window.
  165.     C-x o*                    | Return to the original window.
  166.     C-x )                    | Stop recording.
  167.  
  168. *C-x o (otherThing) is used since Alpha does not record the text typed into
  169. the status bar; changing the buffer with C-x b will require that you hit
  170. RETURN to go to the 'AlphaRefs' window.  C-x o (otherThing), simply
  171. cycles to the window immediately behind the current, front-most, window. 
  172. You will have to be careful that the target window is in the right place
  173. before invoking this macro when using C-x o.
  174.  
  175. Now that you have recorded the macro, you want to make it more useful by 
  176. automatically finding the sentences that you wish to copy into the 
  177. 'AlphaRefs' window.  First, name the macro.  (Use "Name Last Macro"; I 
  178. called the macro 'cpSent2otherWin', but feel free to name it whatever you 
  179. wish).  Next, open your prefs.tcl file (use the Config-> Preferences-> 
  180. Edit Prefs File menu).  Place the cursor at the end of the prefs.tcl file 
  181. and choose "Dump Named Macro" from the Kbd Macros submenu and select 
  182. 'cpSent2otherWin'.  The following proc (or something similar) will appear 
  183. in your prefs.tcl file.
  184.  
  185.     proc cpSent2otherWin {} {
  186.         prevSentence
  187.         setMark
  188.         nextSentence
  189.         copy
  190.         otherThing
  191.         paste
  192.         bind::CarriageReturn
  193.         otherThing
  194.     }
  195.  
  196. The first thing you might wish to do is change the name of the procedure 
  197. so that there is no confusion between the macro (whose definition is 
  198. stored in the arrdefs.tcl file in your Alpha preferences folder) and your 
  199. modifications of it.  You will also want a way to activate the procedure: a 
  200. key binding is the simplest way to invoke your procedure.  The following 
  201. will bind the procedure 'cpSent2otherWina' to ctrl-opt-f (0x03 is the key 
  202. code for 'f').
  203.  
  204.     # ctrl-opt-f
  205.     Bind 0x03 <oz> cpSent2otherWina
  206.  
  207. The code for automatically finding the sentences you want to copy is
  208. simple.  Let's assume that you wish to copy all the sentences with the word
  209. 'Alpha' in them to the 'AlphaRefs' window.  You will need to use a search
  210. command.  The simplest way to proceed is to show you the modified
  211. procedure, then explain what each line does (the line numbers are merely
  212. for reference purposes and should not be included in your procedure).
  213.  
  214.     proc cpSent2otherWina {} {
  215. 2        set pos [getPos]
  216. 3        set theText [search -f 1 -m 0 -s -i 1 "Alpha" $pos]
  217. 4        eval select $theText
  218.         
  219.         prevSentence
  220.         setMark
  221.         nextSentence
  222.         copy
  223.         otherThing
  224.         paste
  225.         bind::CarriageReturn
  226.         otherThing
  227.         
  228. 15        goto [pos::math [lindex $theText 1] + 1]
  229.     }
  230.  
  231. Line 2 uses the AlphaTcl command 'getPos' to return the value of the
  232. current position of the insertion point.  This position value is a number
  233. (in units of bytes) and is stored in the variable 'pos'.  Next, line 3 does
  234. the search (you should take a look at the description of search in 'Alpha
  235. Commands' to find out what the flags mean).  The result of the search is
  236. two values: the initial position of the found text and the final position
  237. of the found text.  Search doesn't move the insertion point, so line 4 
  238. accomplishes this by selecting the found text.  The following lines are the 
  239. same as the original macro.  Line 15 is not necessary since the call to 
  240. nextSentence moves the insertion point beyond the found text, but if our 
  241. macro did not move the point, then some line like 15 would be necessary to 
  242. set up the procedure to be called again without manually moving the point.  
  243. Line 15 uses pos::math to move the point 1 byte past the found text.
  244.  
  245.           Writing Good Macros
  246.  
  247. With practice you will become proficient at constructing macros which work 
  248. in all situations.  The most important principle in creating good macros 
  249. is the use of absolute, rather than relative commands.  In the above 
  250. double-space example, we used C-e to move to the end of the line rather 
  251. than spacing to the end of the line with a series of C-fs.  A good macro 
  252. will successfully work on the target text and prepare itself to be 
  253. repeated.  In the above example, the last command in the macro moves the 
  254. cursor to the next line, precisely where it needs to be for the a repeat 
  255. performance.
  256.  
  257. While macros are an easy way to automate repetitive typing tasks, they are 
  258. not an alternative for writing your own procedures.  There are many things 
  259. that you can't do with a macro.  Loops, if-then conditionals, and searches 
  260. cannot be recorded with a macro.  However, some macros might be good 
  261. starting points for scripting your own procedures.
  262.  
  263.           Things That Don't Work
  264.  
  265. Emacs users will be used to setting up a macro with a search, C-s, 
  266. command.  Alpha is not Emacs!  Text typed into the status bar is not 
  267. recorded.  The command C-s (quickFind) is recorded, but none of the search 
  268. text is.  In order to couple your macro with a search you will have to 
  269. learn a little Tcl (as shown above).
  270.  
  271. Recursive edits do not work in Alpha.  All keystrokes you type during macro
  272. recording are a collected.  (A recursive edit in Emacs is invoked with C-x
  273. q or C-u C-x q and provides a way to pause the macro for user enterable
  274. text.  While in the recursive edit, the keystrokes are not recorded. 
  275. During the macro playback, the macro will pause for the user to enter text
  276. when the recursive edit is encountered.)
  277.  
  278.           Differences Between Alpha and Emacs
  279.  
  280. In the double-space example, we used C-e C-f to position the cursor on the 
  281. next line.  C-n is just as good in Alpha; unlike Emacs, Alpha does not add a
  282. new line to the buffer if C-n is issued on the last line of the file. If 
  283. you use C-n in Alpha and call the macro more times than there are lines in 
  284. the file no extra lines are added.
  285.  
  286.  
  287.     ======================================================================
  288.  
  289.  
  290.  Author: Donavan Hall
  291.  E-mail: <hall@magnet.fsu.edu>
  292.  
  293.